package com.dtsz.m2.ui.activity;

import android.content.ComponentName;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;

import com.dtsz.m2.R;
import com.dtsz.m2.ui.base.BaseActivity;

public class AuthorizationActivity extends BaseActivity {
    private Button bt_pwd;
    private CheckBox checkBox;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        final String token = pageVo.getToken();
        if ("token001".equals(token)) {
            sendIntent(this, LoginAuthorActivity.class);
            finish();
        } else {
            setContentView(R.layout.activity_authorization);
            super.onCreate(savedInstanceState);
            tvActionbarTitle.setText("M2授权登录");
        }
    }

    @Override
    public void initView() {
        super.initView();
        checkBox = findViewById(R.id.cb_info);
        bt_pwd = findViewById(R.id.bt_pwd);
        //给CheckBox设置事件监听
        checkBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView,
                                         boolean isChecked) {
                // TODO Auto-generated method stub
                if (isChecked) {
                    bt_pwd.setTextColor(getResources().getColor(R.color.white));
                    bt_pwd.setBackgroundResource(R.drawable.radius8);
                    bt_pwd.setEnabled(true);
                } else {
                    bt_pwd.setTextColor(getResources().getColor(R.color.colorFont2));
                    bt_pwd.setBackgroundResource(R.drawable.radius08);
                    bt_pwd.setEnabled(false);
                }
            }
        });
    }

    @Override
    public void initClick() {
        super.initClick();
        bt_pwd.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        // super.onClick(v);
        String token = getSharedPreferences("tokenRSA");
        ComponentName componentName = new ComponentName("com.example.wbh", "com.example.wbh.ui.view.LoginActivity");//这里是 包名  以及 页面类的全称
        Intent intent = new Intent();
        switch (v.getId()) {
            case R.id.bt_pwd:
                intent.setComponent(componentName);
                intent.putExtra("token", token);
                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                startActivity(intent);
                finish();
                break;
            case R.id.lay_actionbar_left:
                intent.setComponent(componentName);
                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                startActivity(intent);
                finish();
                break;

        }
    }
}
